qpackage nodes;
import java.util.ArrayList;

public class Node 
{
	public static final int NODE_TYPE_FAILED	= -1;
	public static final int NODE_TYPE_UNKNOWN	= 0;
	public static final int NODE_TYPE_LEAF		= 1;
	public static final int NODE_TYPE_PEER		= 2;
	public static final int NODE_TYPE_ULTRAPEER	= 3;
	
	private String ip;
	private int type;
	
	private ArrayList<Node> connections;
	
	public Node(String IP, int type)
	{
		this.connections = new ArrayList<Node>();
		this.ip = IP;
		this.type = type;
	}
	
	
	public ArrayList<Node> getConnections()
	{
		return connections;
	}
	
	public void addConnection(Node node)
	{
		connections.add(node);
	}
	
	public String getIP()	{
		return this.ip;
	}
	
	public int getType()	{
		return this.type;
	}
	
	public void setType(int Type){
		type = Type;
	}
	
	public int numConnections() {
		return connections.size();
	}
	
	public boolean containsNode(Node node){
		return connections.contains(node);
	}
	
	public boolean containsConnection(String IP){
		return connections.contains(new Node(IP, Node.NODE_TYPE_UNKNOWN));
	}
	
	public String toString()
	{
		return ip;
	}


	@Override
	public boolean equals(Object arg0) {
		Node n = (Node) arg0;
		return ip.equals(n.ip);
	}
	
	
}
